<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
</head>
<body>
<div id="app">
	<div class="header">
		<span>修改快递员信息</span>
	</div>
	<div class="content">
		<table>
			<tr>
				<td class="text-right">手机号码</td><td class="content_right"><input class="input inline-input" placeholder="请输入手机号码" id="phone"> <span class="btn btn-info" id="find">立即查找</span></td>
			</tr>
		</table>
	</div>


	<div class="header">
		<span>查找信息如下</span>
	</div>
	<div class="content">
		<table>
			<tr>
				<td class="text-right">姓名</td><td class="content_right"><input class="input" placeholder="请输入姓名"></td>
			</tr>
			<tr>
				<td class="text-right">手机号码</td><td class="content_right"><input name="phone" class="input" placeholder="请输入手机号码" onblur="checkPhone()"></td>
			</tr>
			<tr>
				<td class="text-right">身份证号码</td><td class="content_right"><input name="ID_Card" class="input" placeholder="请输入身份证号码" onblur="checkId_card()"></td>
			</tr>
			<tr>
				<td class="text-right">密码</td><td class="content_right"><input name="password" class="input" placeholder="请输入密码" onblur="checkPassword()"></td>
			</tr>
			<tr>
				<td></td><td class="content_right"><span class="btn btn-info" id="update">立即修改</span> <span class="btn">重置</span> </td>
			</tr>
		</table>
	</div>
</div>
</body>
<script src="/qrcode/jquery2.1.4.js"></script>
<script src="/layer/layer.js"></script>
<script>


	// 验证密码 6-18位 只包含数字和字母
	function checkPassword(){
		var pattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z\\W]{6,18}$/;
		var password = document.getElementsByName("password")[0].value;
		if (password.match(pattern) == null){
			alert("请输入6-18位只包含数字和字母的密码");
		}else
			console.log("password="+password);
	}

	// \d{17}[\d|x]|\d{15}

	// 验证身份证号码
	function checkId_card(){
		var pattern = /^\d{17}[\d|x]|\d{15}$/;
		var id_card = document.getElementsByName("ID_Card")[0].value;
		if (id_card.match(pattern) == null){
			alert("请输入正确的身份证号");
		}else
			console.log("id_card="+id_card);

	}

	// 验证手机号
	// 0?(13|14|15|18)[0-9]{9}
	function checkPhone(){
		var pattern = /^0?(13|14|15|18)[0-9]{9}$/;
		var phone = document.getElementsByName("phone")[0].value;
		if (phone.match(pattern) == null){
			alert("请输入以13，14，15，18开头的11位的手机号");
		}else
			console.log("phone="+phone);

	}
</script>
<script>
	$(".header:eq(1),.content:eq(1)").hide();
	$(function(){
		var old_phone = '';
		$("#find").click(function(){
			var windowId = layer.load();
			var phone = $("#phone").val();

			$.getJSON("/courier/find.do",{phone:phone},function(data){
				layer.close(windowId);
				//{"status":0,"result":"查询成功","data":{"id":5,"name":"55","phone":"55","ID_Card":"55","password":"55","numberOfPackages":5,"createTime":"Apr 6, 2021, 9:00:04 AM","loginTime":"Apr 6, 2021, 9:00:06 AM"}}
				layer.msg(data.result);
				if(data.status == 0){
					$(".header:eq(1),.content:eq(1)").fadeIn(1000);
					$("input:eq(1)").val(data.data.name);
					$("input:eq(2)").val(data.data.phone);
					$("input:eq(3)").val(data.data.ID_Card);
					$("input:eq(4)").val(data.data.password);

					old_phone = $("input:eq(2)").val();
				}
			})
		});

		$("#update").click(function(){
			var windowId = layer.load();
			var name = $("input:eq(1)").val();
			var phone = $("input:eq(2)").val();
			var ID_Card = $("input:eq(3)").val();
			var password = $("input:eq(4)").val();
			var courier = {
				name:name,
				ID_Card:ID_Card,
				password:password,
				phone: old_phone
			};
			if (old_phone != phone){
				courier.new_phone = phone;
			}

			$.getJSON("/courier/update.do",courier,function(data){
				layer.close(windowId);
				layer.msg(data.result)

				if(data.status == 0){
					//修改成功
					$(".header:eq(1),.content:eq(1)").hide();
				}
			})
		});
	});
</script>
</html>
